fix: support single-level and default packages for all runnables#254
Conversation
The tree-sitter query for runnables was only capturing `scoped_identifier` for package names. This caused it to completely miss single-level packages, e.g., `package example;`, which are parsed as a basic `identifier`. This updates the query to match both `identifier` and `scoped_identifier`.
|
We require contributors to sign our Contributor License Agreement, and we don't have @fredyw on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'. |
|
@cla-bot check |
|
The cla-bot has been summoned, and re-checked this pull request! |
|
@fredyw thanks for the contribution. Could you expand the description explaining all the additions included in the PR? |
|
Consider also to extend the PR covering what #248 does for files without a package |
Done. |
Done. I have incorporated your changes in this PR. I also added missing tests. |
|
Thanks for the additions, both in the code and in the PR description. Let's include nested tests for full feature coverage and then we can proceed merging the changes. PS. Run `just lint' a couple of times to be sure the checks for the PR become green. |
|
Also double check that everything works as expected by double testing against, there might be something off as all main executes > Task :run
Dotted package main: com.exampleeven though I executed the main from the file SimpleMain |
That's because you have The existing One we have that configured, it will work just correctly when running |
Nested tests added. I also fixed the format and linter errors. |
|
@fredyw oh thanks for pointing that out, I completely missed that from the gradle file. Kudos for spotting that. |
Fix the issue where Zed fails to recognize "Run" and "Test" buttons for Java files in single-level packages, e.g.,
package example;or the default package (no package declared).Changes:
runnables.scm: Update the package query to match both simpleidentifierandscoped_identifiernodes. Make the package declaration optional across all patterns (main methods, JUnit test methods, and test classes) to enable default package support.tasks.json: Add conditional shell logic (if [ -n "$package" ]...) to correctly construct the fully qualified class name. This prevents the generation of invalid commands (likejava .Main) when executing code in the default package.Testing:
instasnapshot tests intests/java.rsfor better maintainability and alignment with core Zed extensions.Fixes #241.